package com.teamwork.ZuccEcho.Repository;

import com.teamwork.ZuccEcho.Entity.Model;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface ModelApiRepository extends JpaRepository<Model, Long>, JpaSpecificationExecutor<Model> {
    Model findById(long id);

    @Query(value="select count(*) from model", nativeQuery = true)
    Long countAll();

    @Query(value="select * from model where model.m_id = ?1", nativeQuery = true)
    List<Model> findModelByModelId(long m_id);

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO model(m_illustration,m_name) VALUES (?1,?2)",nativeQuery = true)
    void insertModel(String model_mIllustration,String model_mName);

    @Transactional
    @Modifying
    @Query(value="DELETE from model where model.m_id= ?1", nativeQuery = true)
    void deleteModelByMId(long model_Id);

    @Transactional
    @Modifying
    @Query(value="UPDATE model SET m_name = ?1 , m_illustration = ?2 WHERE m_id = ?3", nativeQuery = true)
    void modifyModelByMId(String name,String illustration,long model_Id);
}